//引入canvas的宽高
import config from "../../config.js";

export default class Background{
    constructor(ctx) {

        //一层一层的接收到canvas
        this.ctx = ctx

        this.src = "../../flappybird/bg_day.png" //引入背景图片

        this.img = new Image() //构造函数Image实例化出一个背景图片对象img
        this.img.src = this.src //将引入的背景图片赋值给实例化出来的背景图片对象img
        this.speed = -2
        this.x = 0
    }
    render(){
        this.x += this.speed
        if(this.x <= - config.width) this.x = 0
        this.ctx.drawImage(this.img,this.x,0,config.width,config.height) //将img传进去绘制，从坐标（this.x，0）开始绘制
        this.ctx.drawImage(this.img,this.x + config.width,0,config.width,config.height)
    }
}